package leetCode.offer57;

import java.util.HashSet;
import java.util.Set;

public class Solution3 implements Solution{
    @Override
    public int[] twoSum(int[] nums, int target) {
        Set<Integer> set = new HashSet<>();
        int[] result = new int[2];
        for(int i=0;i<nums.length;i++){
            if(set.contains(target-nums[i])){
                result[0] = nums[i];
                result[1] = target-nums[i];
                break;
            }else{
                set.add(nums[i]);
            }
        }
        return result;
    }
}
